_Pragma("once");

#include <string>
#include <cstring>
#include <cstdio>
#include <map>

#define LOAD_CONFIG_FIELD(ROOT, ENTITY, FIELD, DEFAULT_VALUE) ENTITY.FIELD = (pEntry = cJSON_GetObjectItemCaseSensitive(ROOT, #FIELD)) ? pEntry->valuestring : (DEFAULT_VALUE)
#define LOAD_CONFIG_INT_FIELD(ROOT, ENTITY, FIELD, DEFAULT_VALUE) ENTITY.FIELD = (pEntry = cJSON_GetObjectItemCaseSensitive(ROOT, #FIELD)) ? pEntry->valueint : (DEFAULT_VALUE)


#define LOAD_CONFIG_STRING(ROOT, FIELD, DEFAULT_VALUE) (pEntry = cJSON_GetObjectItemCaseSensitive(ROOT, #FIELD)) ? pEntry->valuestring : (DEFAULT_VALUE)
#define LOAD_CONFIG_INT(ROOT, FIELD, DEFAULT_VALUE) (pEntry = cJSON_GetObjectItemCaseSensitive(ROOT, #FIELD)) ? pEntry->valueint : (DEFAULT_VALUE)


#define SAVE_CONFIG_FIELD(ROOT, ENTITY, FIELD)  cJSON_AddStringToObject(ROOT, #FIELD, ENTITY.FIELD.data())
#define SAVE_CONFIG_INT_FIELD(ROOT, ENTITY, FIELD)  (pEntry = cJSON_AddNumberToObject(ROOT, #FIELD, ENTITY.FIELD)) ? pEntry->valueint = ENTITY.FIELD : (ENTITY.FIELD)

#define SAVE_CONFIG_STRING(ROOT, VALUE, FIELD)  cJSON_AddStringToObject(ROOT, #FIELD, VALUE.data())
#define SAVE_CONFIG_INT(ROOT, VALUE, FIELD)  (pEntry = cJSON_AddNumberToObject(ROOT, #FIELD, VALUE)) ? pEntry->valueint = VALUE : (VALUE)



constexpr int MAX_BUFFER_SIZE = 10240;
constexpr int STRING_BUFFER_SIZE = 1024;


namespace Utility {

    using StringMap = std::map<std::string, std::string>;



}
